
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;

using Swaf;
using Swaf.Container;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Security;
using Swaf.Gui;

using UserLogin.Gui;
using Syrinx.Gui;
namespace UserManagement.Gui
{
	public class UserManagementBizProc : BaseBusinessProcess
	{
		public UserManagementBizProc(ActiveBizProc procState)
			: base(procState)
		{
		}

		protected override void setupRuleNames()
		{
			base.m_getBizObjDetailsRule = "getUser";
			base.m_getBizObjListRule = "getCompanyUserList";
			base.m_updateBizObjRule = "updateUserInfo";
			base.m_deleteBizObjRule = "deleteUser";
		}

		public override IResults updateBizObj(IBizObj obj)
		{
			return base.updateBizObj(obj);
		}
		public override IBizObj createNewBizObj()
		{
			object cmpId = m_procState.get("pid");
			IBizObj user = App.bizObjMgr.create("User");
			Swaf.BGuid.Guid userId = new Swaf.BGuid.Guid();
			user.put("id", userId);
			user.put("companyId", cmpId == null ? ActiveCompanyId : cmpId);
			user.put("settings.id", userId);
			user.put("limits.id", userId);
			user.put("contact.id", user.get("id"));
			user.put("contact.defaultAddress.id", new Swaf.BGuid.Guid());
			user.put("contact.isUser", true);
			user.put("contact.typeId", App.appData["contactOptions.types.(name:Employee).id"]);
			return user;
		}

		protected override Privileges CurrentEditPrivilege
		{
			get { return CurrentPrincipal.getPrivilege("AppFunctions.ManageUsers"); }
		}
	}
}
